/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package east2west.action;

import east2west.dao.FlightDAO;
import east2west.dao.HotelDAO;
import east2west.dto.CarsDTO;
import east2west.dto.FlightsDTO;
import east2west.dto.HotelDTO;
import east2west.dto.SaleTourDTO;
import east2west.dto.TourDTO;
import east2west.service.CarService;
import east2west.service.FlightsService;
import east2west.service.TourService;
import java.util.ArrayList;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author Admin
 */
public class PagingAction extends DispatchAction{
    
    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
     private static final String HOTEL = "hotel";
       private static final String FLIGHT = "flight";
       private static final String CAR = "car";
        private static final String TOUR = "tour";
       private static final String SALETOUR = "saletour";
     float min = 0;
    float max = 0;
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
 public ActionForward pagingFlight(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FlightDAO dao = new FlightDAO();
        ArrayList<FlightsDTO> list = dao.readByAll();
        request.setAttribute("list", list);
        request.setAttribute("page", "flight.page");
        return mapping.findForward(SUCCESS);
    }

public ActionForward pagingHotel(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
       HotelDAO dao = new HotelDAO();
        ArrayList<HotelDTO> list = dao.readByAll();
        request.setAttribute("list", list);
        request.setAttribute("page", "hotel.page");
        return mapping.findForward(HOTEL);
    }

public ActionForward pagingTour(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
     TourService tourSer = new TourService();
        ArrayList<TourDTO> listTour = new ArrayList<TourDTO>();
        ArrayList<TourDTO> listTourMinMax = new ArrayList<TourDTO>();
        listTour = tourSer.readByAll();
        for (Iterator<TourDTO> it = listTour.iterator(); it.hasNext();) {
            TourDTO tourDTO = it.next();
            int id = tourDTO.getTourId();
            max = tourSer.getMax(id);
            min = tourSer.getMin(id);
            tourDTO.setMin(min);
            tourDTO.setMax(max);
            listTourMinMax.add(tourDTO);

        }

        request.setAttribute("listTour", listTourMinMax);

        request.setAttribute("page", "tourAd.page");
        return mapping.findForward(TOUR);
    }

public ActionForward pagingCar(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
      CarService serCar = new CarService();
        ArrayList<CarsDTO> listCar = serCar.readByAll();
        request.setAttribute("listCar", listCar);
        request.setAttribute("page", "carAdd.page");
        return mapping.findForward(CAR);
    }

public ActionForward pagingSaleTour(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
     TourService tourSer = new TourService();
     ArrayList<SaleTourDTO> listSale = tourSer.listAllSaleTour();
        request.setAttribute("listSale", listSale);
        request.setAttribute("page", "saletour.page");
        return mapping.findForward(SALETOUR);
    }



public ActionForward pagingFlightNew(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
      FlightsService serFlights = new FlightsService();
        ArrayList<FlightsDTO> list = serFlights.readByAll();
        request.setAttribute("list", list);
        return mapping.findForward(FLIGHT);
    }
}
